package indi.kider.server.applet.service;


import indi.kider.common.model.apartment.HouseApplet;
import indi.kider.common.model.apartment.Houses;
import indi.kider.common.model.employee.Employee;
import indi.kider.common.model.employee.Enterprise;
import indi.kider.server.apartment.mapper.HousesMapper;
import indi.kider.server.applet.model.User;
import indi.kider.server.employee.mapper.EmployeeMapper;
import indi.kider.server.employee.mapper.EnterpriseMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.util.ArrayList;
import java.util.List;

@Service
@SuppressWarnings("all")
public class EnterpriseServiceImpl implements EnterpriseService {

    @Autowired
    private EnterpriseMapper enterpriseMapper;
    @Autowired
    private HousesMapper housesMapper;
    @Autowired
    private EmployeeMapper employeeMapper;

    @Override
    public List<Enterprise> getEnterprise() throws Exception {
        List<Enterprise> enterpriseList = new ArrayList<>();
        Example enterprise = new Example(Enterprise.class);
        enterprise.createCriteria().andEqualTo("apartmentType", "1");
        return enterpriseMapper.selectByExample(enterprise);
    }

    @Override
    public List<Houses> getPendingReservation(User user) throws Exception {
        Long enterpriseId = user.getEnterpriseId();
        Integer sex = user.getSex();
        Long communityId = user.getCommunityId();
        if (enterpriseId == null) {
            enterpriseId = 1l;
        }
        return housesMapper.getPendingReservation(enterpriseId, sex,communityId);
    }

    @Override
    public List<Employee> getSameEnterprise(User user) throws Exception {
        List<Employee> employeeList = new ArrayList<>();
        Employee employee = new Employee();
        employee.setId(user.getId());
        employee.setState(1);
        Employee e = employeeMapper.selectOne(employee);
        //if("2".equals(e.getRoles())){
        Example enterprise = new Example(Employee.class);
        enterprise.createCriteria().andEqualTo("enterpriseId", e.getEnterpriseId()).andEqualTo("roles", "3");
        employeeList = employeeMapper.selectByExample(enterprise);
        //}
        return employeeList;
    }

    @Override
    public List<Enterprise> getCommunityEnterprise(HouseApplet houseApplet) throws  Exception{
            Example enterpriseE = new Example(Enterprise.class);
            enterpriseE.createCriteria().andEqualTo("enId",houseApplet.getEnterpriseId());
            return enterpriseMapper.selectByExample(enterpriseE);
    }


}
